package com.etlmaster.executor.steps.load;

import com.etlmaster.executor.Step;
import com.etlmaster.executor.StepMeta;
import com.etlmaster.executor.annotation.StepInstruction;
import com.etlmaster.executor.bigdata.hbase.HbaseBulkLoad;
import com.etlmaster.executor.utils.DataCollectionUtils;
import com.etlmaster.executor.utils.StepState;


/**
 * @author Wugf
 * @date 2016-11-10
 */
@StepInstruction("hbaseLoader")
public class HbaseBulkLoadStep extends Step{

	private HbaseBulkLoadStepMeta meta;
	public HbaseBulkLoadStep(StepMeta meta) {
		super(meta);
		this.meta=(HbaseBulkLoadStepMeta) meta;
	}

	@Override
	protected int handle() {
		String tmpDir=DataCollectionUtils.getProperties("tempHdfsDir")+"/"+this.hashCode();
		HbaseBulkLoad bulkLoader=new HbaseBulkLoad(meta.getUser(),meta.getTableName(),meta.getUri(),tmpDir,meta.getColumnFamilys(),meta.getFileFields(),meta.getRowKeyColumns(),meta.getSeprator());
		try{
			boolean isSuccess=bulkLoader.bulkLoad();
			if(isSuccess)
				return StepState.RUNNING_SUCCESSED;
			
		}catch(Exception e){
			meta.log("ERROR",e.getMessage());
			
		}
		return StepState.RUNNING_FAILED;
		
	}

	@Override
	public boolean stop() {
		// TODO Auto-generated method stub
		return false;
	}

}
